/**
 * User: alesj
 * Date: 11.1.2006
 * Time: 12:26:20
 * 
 * (C) Genera Lynx d.o.o.
 */

package com.alesj.blueberry.par.basic;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;
import java.util.HashSet;
import java.io.Serializable;

/**
 * Each request is logged.
 * Holding all possible information gathered from request.
 *
 * @author <a href="mailto:ales.justin@genera-lynx.com">Ales Justin</a>
 */
@Entity
@Table(name = "request_entry")
public class RequestEntry implements Serializable {

    private Integer id;
    private String messageId;
    private long timestamp;
    private String number;
    private String message;
    private Date serverDate;
    private Date submitDate;
    private Date deliveryDate;
    private ValidationError validationError;
    private GameObject gameObject;
    private Set<ErrorLog> errorLogs;

    public RequestEntry() {
    }

    public RequestEntry(long timestamp, String messageId, String number, String message) {
        this.timestamp = timestamp;
        this.messageId = messageId;
        this.number = number;
        this.message = message;
    }

    public String toString() {
        return "RE (" + getId() + ", " + getServerDate() + ", " + getTimestamp() + ", " + getMessageId() + ")";
    }

    @Id
    @GeneratedValue
    @Column(name = "request_entry_id", unique = true, nullable = false)
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name = "smsc_message_id")
    public String getMessageId() {
        return messageId;
    }

    public void setMessageId(String messageId) {
        this.messageId = messageId;
    }

    @Column(name = "time_stamp")
    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Date getServerDate() {
        return serverDate;
    }

    public void setServerDate(Date serverDate) {
        this.serverDate = serverDate;
    }

    public Date getSubmitDate() {
        return submitDate;
    }

    public void setSubmitDate(Date submitDate) {
        this.submitDate = submitDate;
    }

    public Date getDeliveryDate() {
        return deliveryDate;
    }

    public void setDeliveryDate(Date deliveryDate) {
        this.deliveryDate = deliveryDate;
    }

    @OneToOne(mappedBy = "requestEntry")
    public ValidationError getValidationError() {
        return this.validationError;
    }

    public void setValidationError(ValidationError validationError) {
        this.validationError = validationError;
    }

    @OneToOne(mappedBy = "requestEntry")
    public GameObject getGameObject() {
        return gameObject;
    }

    public void setGameObject(GameObject gameObject) {
        this.gameObject = gameObject;
    }

    @OneToMany(mappedBy = "requestEntry")
    public Set<ErrorLog> getErrorLogs() {
        return errorLogs;
    }

    public void setErrorLogs(Set<ErrorLog> errorLogs) {
        this.errorLogs = errorLogs;
    }

    public void addErrorLog(ErrorLog errorLog) {
        if (errorLogs == null) {
            errorLogs = new HashSet<ErrorLog>();
        }
        errorLogs.add(errorLog);
    }

}
